﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class admin_AttendanceInfoList : System.Web.UI.Page
{
    static DataSet ds = null;
    public static AttendanceTime attendanceTime;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 80)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if (!IsPostBack)
        {
            attendanceTime = AttendanceTimeManager.showIt(Server.MapPath(@"~/companyFiles/AttendanceTime.xml"));
            ds = AttendanceInfoManager.FindAttendanceInfoByUserAll((TarreOA.TarreOAModels.User)Session["user"]);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "showAttendanceInfo")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "window.showModalDialog ('AttendanceInfoShow.aspx?aid=" + e.CommandArgument.ToString() + "', '','status:no;center:yes;scroll:no;resizable:no;help:no;dialogWidth:550px;dialogHeight:400px');", true);
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        TarreOA.TarreOAModels.User user=(User)Session["user"];
        if (txtBeginDate.Text !="" && txtEndDate.Text!="")
        {
            ds=AttendanceInfoManager.FindBlurAttendanceInfo(user.UserId,txtBeginDate.Text,txtEndDate.Text);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else if (txtBeginDate.Text=="" && txtEndDate.Text!="")
        {
            ds=AttendanceInfoManager.FindBlurAttendanceInfo(user.UserId,"2004-1-1",txtEndDate.Text);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else if(txtBeginDate.Text !="" && txtEndDate.Text=="")
        {
            ds = AttendanceInfoManager.FindBlurAttendanceInfo(user.UserId, txtBeginDate.Text, System.DateTime.Now.ToShortDateString());
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else
        {
            ds = AttendanceInfoManager.FindBlurAttendanceInfo(user.UserId, "2004-1-1", System.DateTime.Now.ToShortDateString());
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            ((Label)e.Row.FindControl("lblComeAMHead")).Text = "上班"+attendanceTime.ComeAM;
            ((Label)e.Row.FindControl("lblBackAMHead")).Text = "下班" + attendanceTime.BackAM;
            ((Label)e.Row.FindControl("lblComePMHead")).Text = "上班" + attendanceTime.ComePM;
            ((Label)e.Row.FindControl("lblBackPMHead")).Text = "下班" + attendanceTime.BackPM;
        }
    }
}
